package com.example.xymarket.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xymarket.common.MyBitMap;
import com.example.xymarket.myView.StatusBar;
import com.example.xymarket.R;
import com.example.xymarket.po.Order;
import com.google.gson.Gson;

public class OrderDetailActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_detail);
        StatusBar.setStatusBarColor(this,StatusBar.yellow);
        init();
    }

    @SuppressLint("SetTextI18n")
    public void init()
    {
        Intent intent=getIntent();
        String orderStr=intent.getStringExtra("order");
        Order order= new Gson().fromJson(orderStr,Order.class);
        byte[] bits=intent.getByteArrayExtra("bitmap");
        Bitmap bitmap= MyBitMap.getPicFromBytes(bits,new BitmapFactory.Options());
        TextView id=(TextView) findViewById(R.id.order_id);
        TextView name=(TextView) findViewById(R.id.order_goods_name);
        TextView time=(TextView) findViewById(R.id.order_time);
        TextView merchant=(TextView) findViewById(R.id.order_merchant_name);
        TextView price=(TextView) findViewById(R.id.order_price);
        ImageView avatar=(ImageView) findViewById(R.id.order_goods_avatar);

        avatar.setImageBitmap(bitmap);
        try {
            id.setText("订单号码：" + order.getId().toString());
            name.setText("商品名称：" + order.getGoods().getTitle());
            time.setText("交易时间：" + order.getCreateTime().toString());
            price.setText("订单金额：" + order.getGoods().getPrice().toString());
            merchant.setText("店铺编号：" + order.getMerchantId().toString());
        }
        catch (Exception e)
        {
            Log.d("e",e.toString());
        }
    }

    public void back(View view)
    {
        Intent intent=new Intent(this,OrderActivity.class);
        startActivity(intent);

    }

}